// EOSQLConnection.cs
//
//  Copyright (C) 2008 Whitemice Consulting
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//
using System;
using System.Collections.Generic;

namespace Whitemice.EOMono
{
  public abstract class EOSQLConnection
  {   
    public EOSQLConnection()
    {
    }
    
    public IList<IEORecord> Run(string command, params object[] args)
    {
      IEOCommand        commandObject = null;
      IList<IEORecord>  results = null;
      string            entity, verb;
      Type              commandClass;
     
      entity = command.Split(':')[0];
      verb = command.Split(':')[1];
      commandClass = EOManager.ClassForName(verb);
      if (commandClass == null)
        throw new EONoClassForCommandException(verb);
      /*
      Console.WriteLine("Going to create {0} for command {1}",
        commandClass,
        command);
       */
      commandObject = (IEOCommand)Activator.CreateInstance(
                         commandClass,
                         new object[] { this, entity });
      if (commandObject != null)
        results = commandObject.Run(args);
      return results;
    } // end Run    
  }
}
